package com.hzvdvmc.autosale.sale.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.InputFilter;
import android.text.LoginFilter;
import android.text.method.DigitsKeyListener;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hzvdvmc.autosale.R;

/**
 * Created by william on 2018/1/12.
 */

public class InputDialog extends BaseDialog {

    private TextView tvTitle;
    private EditText edtInput;
    private Button btnCancel;
    private Button btnYes;
    private int inputType;

    public InputDialog(@NonNull Context context, int themeResId, int inputType) {
        super(context, themeResId);
        this.inputType = inputType;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_input);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        edtInput = (EditText) findViewById(R.id.edt_input);
        btnCancel = (Button) findViewById(R.id.btn_cancel);
        btnYes = (Button) findViewById(R.id.btn_yes);
        edtInput.setInputType(inputType);

    }

    public void setCurrentValue(String value) {
        edtInput.setText(value);
        edtInput.setSelection(value.length());
    }

    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    public void setEditFilter(String digits) {
        DigitsKeyListener instance = DigitsKeyListener.getInstance(digits);
        edtInput.setKeyListener(instance);
    }

    public void setEditLength(int max) {
        edtInput.setFilters(new InputFilter[]{new InputFilter.LengthFilter(max)});
    }


    public String getInputContent() {
        return edtInput.getText().toString();
    }

    public void setOkOnClickListenter(View.OnClickListener onClickListenter) {
        btnYes.setOnClickListener(onClickListenter);
    }

    public void setCancelOnClickListenre(View.OnClickListener onClickListenter) {
        btnCancel.setOnClickListener(onClickListenter);
    }


}
